06. Can You Write a Palindrome Function?

Can You Write a Palindrome Function?

Question:

Start Quiz:

INSTRUCTOR NOTE:

In this video you'll see str.reverse(). This is basically a way to say during the interview: "Don't worry about the actual code to reverse a string. Pretend that this exists so we can move on to the next part of the interview."

Of course if you wanted to make this work, you could just do it naively like this:

String.prototype.reverse=function(){return this.split("").reverse().join("");}

and then you can type something like this and it will work:

console.log("Udacity".reverse());

The higher level point is that interviewing is a dialogue. If you know your Javascript strings inside and out, you could ask the interviewer before you write any code: "What about astral symbols or Unicode? Should my reverse function work for those too?"

If you don't know what astral symbols are or what Unicode is don't worry. You can read through this thread on StackOverflow to see why they are problematic for string reversal in ECMAScript 5. Consider reading about Unicode as well.

More importantly, be sure to clarify the bounds of the problem you are trying to solve to the best of your understanding and the interviewer should guide you to the parts of the problem they want to work on with you. It's all about collaboration!

The down side of interviewing for Front End Web Development is that there is a growing concern that the interviewing system used by many companies is broken (with some hopeful responses) in the sense that your interviewers are asking you algorithm questions instead of Front End Framework questions which are more related to what you'd actually be doing in your job.